package com.shanlitech.et.utils;

import org.springframework.boot.ApplicationHome;
import org.springframework.core.io.ClassPathResource;

import java.io.*;
import java.util.Properties;

public class ConfigUtil {

    public static String get(String key) {
        ApplicationHome home = new ApplicationHome(ConfigUtil.class);
        File path = home.getSource().getParentFile();
        InputStream is;
        String value = null;
        try {
            Properties prop = new Properties();
            if(new File(path + "/application.properties").exists()) {
                is = new BufferedInputStream(new FileInputStream(path + "/application.properties"));
            } else {
                //is = new BufferedInputStream(new FileInputStream();
                is = ConfigUtil.class.getClassLoader().getResourceAsStream("application.properties");
            }
            prop.load(is);     ///加载属性列表
            value = prop.getProperty(key);
            is.close();
        } catch (IOException e) {
            System.out.println("Read ConfigFile Error!");
            e.printStackTrace();
            return "";
        }
        return value;
    }
}
